const Mock = require("mockjs");

const data = Mock.mock({
  "list|60": [
    {
      id: "@id",
      "stateflag|1": [true, false],
      classifyName: "@ctitle",
      classifyNameSeach: "",
      classify: "@ctitle",
      classifyIcon: "",
      classifySort: "",
      "classifyState|1": [true, false],
      "classifyButton|+1": ["添加项", "编辑", "删除"],
      "children|2-3": [
        {
          id: "@id",
          classifyName: "@ctitle",
          classify: "@ctitle",
          "classifyState|1": [true, false],
        },
      ],
    },
  ],
});

Mock.mock("/getdirectivedata", "post", (req) => {
  const { pageIndex, pageSize, keyword, shopInput } = JSON.parse(req.body);
  let newList = JSON.parse(JSON.stringify(data.list));
  if (keyword) {
    newList = newList.filter((item) => item.name.includes(keyword));
  }
  if (shopInput) {
    newList = newList.filter((item) => item.title.includes(shopInput));
  }
  if (pageIndex && pageSize) {
    newList = newList.slice((pageIndex - 1) * pageSize, pageIndex * pageSize);
  }
  return {
    code: 20000,
    data: newList,
    total: data.list.length,
  };
});
